#include "project1.h"
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;

int * CreateData(int sizeOfArray)
{
    cout << "Creating data for test" << endl;
    int * data;
    cout << "Allocating Memory" << endl;
    data = new int[sizeOfArray];
    cout << "Completed Allocation of Memory" << endl;
    cout << "Assigning Random Values" << endl;
    for(int i = 0; i < sizeOfArray; i++)
    {
        data[i] = rand();     
    }
    cout << "Completed assignments" << endl;
    return data;
}

long ReverseArray(int * dataArray, int sizeOfDataArray)
{
    cout << "Running Algorithm: Reverse Array" << endl;
    long startTime = clock();
    int middle = sizeOfDataArray / 2;
    for(int i = 0; i < middle; i++)
    {
        int temp = dataArray[i];
        dataArray[i] = dataArray[sizeOfDataArray - i - 1];
        dataArray[sizeOfDataArray - i - 1] = temp;
    }
    long endTime = clock();
    cout << "Finished Algorithm: Reverse Array" << endl;
    return endTime - startTime;
}

long BubbleSort(int* dataArray, int sizeOfDataArray) 
{
    cout << "Running Algorithm: Bubble Sort" << endl;
    long startTime = clock();
    for (int i = 0; i < sizeOfDataArray - 2; i++) 
    {
        for (int j = 0; j < sizeOfDataArray - 1 - i; j++) {
            if (dataArray[j + 1] < dataArray[j]) {
                int temp = dataArray[j];
                dataArray[j] = dataArray[j + 1];
                dataArray[j + 1] = temp;
            }
        }
    }
    long endTime = clock();
    cout << "Finished Alogrithm: Bubble Sort" << endl;
    return endTime - startTime;
}

long SelectionSort(int* dataArray, int sizeOfDataArray) 
{
    cout << "Running Algorithm: Selection Sort" << endl;
    long startTime = clock();
    for (int i = 0; i < sizeOfDataArray - 2; i++) 
    {
        int min = i;
        for (int j = i + 1; j < sizeOfDataArray; j++) {
            if (dataArray[j] < dataArray[min]) {
                min = j;
            }
            int temp = dataArray[i];
            dataArray[i] = dataArray[min];
            dataArray[min] = temp;
        }
    }
    long endTime = clock();
    cout << "Finished Algorithm: Selection Sort" << endl;
    return endTime - startTime;
}
